var app = getApp();
var memberUtil=require('../../utils/memberUtil');
Page({
	/* 页面的初始数据 */
	data: {
		tabs: [
			{
				url: '../../../images/consum1.png',
				name: "消费金",
				type:0
			},
			{
				url: '../../../images/consum2.png',
				name: "佣金",
				type:1
			},
			{
				url: '../../../images/consum3.png',
				name: "积分",
				type:2
			}
		],     //展示的数据
		slideOffset: 0, //指示器每次移动的距离
		activeIndex: 0, //当前展示的Tab项索引
		contentHeight: 0,//页面除去头部Tabbar后，内容区的总高度，计算得到
		xfjItems:[],
		yjItems:[],
		jfItems:[]
	},
	/* 生命周期函数--监听页面加载 */
	onLoad: function (options) {
		var that=this;
		that.setData({
			userInfo: wx.getStorageSync("loginUserInfo").userInfo==undefined?"":wx.getStorageSync("loginUserInfo").userInfo,
		});
		wx.setNavigationBarTitle({
			title: '账户明细'
		})
		var that = this;
		wx.getSystemInfo({
			success: function (res) {
				that.setData({
					//计算相关宽度
					sliderWidth: res.windowWidth / that.data.tabs.length,
					sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex,
					contentHeight: res.windowHeight - res.windowWidth / 750 * 112, //计算内容区高度，rpx -> px计算
				});
			}
		});
		if(that.data.userInfo.id==undefined) {
			memberUtil.getLogin(app,0,1,that,2);
		}
	},

	bindChange:function (e) {
		var current = e.detail.current;
		this.setData({
			activeIndex: current,
			sliderOffset: this.data.sliderWidth * current
		});
		// console.log("bindChange:" + current);
	},

	navTabClick: function (e) {
		this.setData({
			sliderOffset: e.currentTarget.offsetLeft,
			activeIndex: e.currentTarget.id
		});
		// console.log("navTabClick:" + e.currentTarget.id);
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		var that=this;
	//会员积分明细
	that.jf();
		that.yj();
		that.xfj();

	},
	/**
	 * 会员积分明细查询
	 */
	jf: function () {
		var that=this;
		var memberIdJson = { memberId:that.data.userInfo.id}
		wx.request({
			url: app.globalData.baseUrl+ '/member/findIntegralList',
			method: 'POST',
			data: JSON.stringify(memberIdJson),
			success:function(e){
				if(e.statusCode==200){
					that.setData({
						jfItems:e.data
					})
				}
			}
		})
	},
	/**
	 * 会员佣金明细查询
	 */
	yj: function () {
		var that=this;
		var memberIdJson = { memberId:that.data.userInfo.id}
		wx.request({
			url: app.globalData.baseUrl+ '/member/findCommissionList',
			method: 'POST',
			data: JSON.stringify(memberIdJson),
			success:function(e){
				if(e.statusCode==200){
					that.setData({
						yjItems:e.data
					})
				}
			}
		})
	},
	/**
	 * 会员消费金明细查询
	 * consumeType：
	 消费类型（0积分购物车消费金花费；1直接购买商品，也就是订单需要微信支付金额，2购买卡券 ）
	 */
	xfj: function () {
		var that=this;
		var memberIdJson = { memberId:that.data.userInfo.id}
		wx.request({
			url: app.globalData.baseUrl+ '/member/findConsumeMoneyList',
			method: 'POST',
			data: JSON.stringify(memberIdJson),
			success:function(e){
				if(e.statusCode==200){
					that.setData({
						xfjItems:e.data
					})
				}
			}
		})
	},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
		var that=this;
		return {
			title: '我的二维码',
			path: "/pages/shop/shareSuccess?parentId=" + that.data.userInfo.id + "&enterType=0",
			imageUrl: app.globalData.loginUserInfo.erweimaUrl
		}
	}
})